import urllib.request
import json


if __name__ == '__main__':
    # urlopen 返回 HTTPResponse 对象
    r = urllib.request.urlopen('http://httpbin.org/get')
    # HTTPResponse 对象信息
    print(r.status, ' ', r.reason)
    # body内容获取
    text = r.read()
    obj = json.loads(text)
    print(obj)
    # headers获取, r.headers是HTTPMessage对象
    for k, v in r.headers._headers:
        print(k, ': ', v)



